<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/9/21
 * Time: 下午8:58
 */
class RealController extends AdminBaseController {

    public function login(){
        $this->common1('login', '5分钟登录数据');
    }

    public function online(){
        $this->common('online', '5分钟在线数据');
    }

    public function reg(){
        $this->common1('reg', '5分钟创角数据');
    }

    public function pay(){
        $this->common1('pay', '5分钟充值数据');
    }
    
    private function common($type, $name){
    	$filter = new PubFilter();
    	$grid   = new PubGrid();
    	$chart  = new PubChart();
    
    	$filter->addServerFilter1(false)
            ->addPort()          
    	->addFilter('time', 'timerange', PubFunc::t('时间'), array('value' => PubDateRange::getLastDayRange(0)));
    
    	$this->setTitle($name);
    	$params = $filter->get();
     	$h_d_result = RealService::getData($type, $params);
    	$header = $h_d_result['header'];    	
    	$data = $h_d_result['data'];
    	
    	$this->out['is_exit']   = 1;  // 存在数据
    	if(count($header) == 1){
    		$header = RealService::getHeader($params);
    		$data = array();
    		$this->out['is_exit']   = 2; //不存在数据
    	}
    	
    	

//     	$header = RealService::getHeader($params);
//     	$data = $h_d_result['data'];
    	
    	$config = RealService::getChart($params, $data);
    	$grid->addGrid($header, $data, array(
    			'name'  =>'数据',
    			'order' => array('date', 'desc'),
    			'fix'   => array(
    					'col' => 1
    			)
    	));
    
    	$chart->addChart('chart', $config['data'], array(
    			'config'    => $config['setting'],
    			'name'      => $name
    	));
    
    	$this->out['grid']   = $grid->show();
    	$this->out['filter'] = $filter->show();
    	$this->out['chart']  = $chart->show();
    	$this->out['is_log'] = 1;
    	
    	
    }

    private function common1($type, $name){
        $filter = new PubFilter();
        $grid   = new PubGrid();
        $chart  = new PubChart();

        $allServer = false;
        if($type != 'online'){
            if($type == 'pay'){
                //$filter->addOsFilter(true);
            }else{
                //$filter->addOsFilter();
            }
            //$allServer = true;
        }
        
        $lod_special_id = $this->R('special_id');
        $lodos = $this->R('os');
        $filter->addSpecialFilter(false,2);
        $filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2);


        //$filter->addServerFilter($allServer)
        $filter->addFilter('time', 'timerange', PubFunc::t('时间'), array('value' => PubDateRange::getLastDayRange(0)));

        $this->setTitle($name);
        $params = $filter->get();
        //这里的time_start和time_end不参与到上次筛选的session当中
        $time_start = $params['time_start'];
        $time_end = $params['time_end'];     
        $params = $this->indexCommon($params);
        $params['time_start'] = $time_start;
        $params['time_end'] = $time_end;
        if($type == 'online'){
            $params['os'] = 'ALL';
        }
        //var_dump($params);
        $header = RealService::getHeader1($params);
        $data = RealService::getData1($type, $params);
        $config = RealService::getChart($params, $data);

        $grid->addGrid($header, $data, array(
            'name'  =>'数据',
            'order' => array('date', 'desc'),
        	'fix'   => array(
        			'col' => 1
        	)
        ));

        $chart->addChart('chart', $config['data'], array(
            'config'    => $config['setting'],
            'name'      => $name
        ));

        $this->out['grid']   = $grid->show();
        $this->out['filter'] = $filter->show();
        $this->out['chart']  = $chart->show();
        $this->out['is_ana'] = 2;
    }

}